$(function () {
    $('#desc').editable({
        inlineMode: false,
        alwaysBlank: true,
        height: '500px', //高度
        minHeight: '200px',
        language: "zh_cn",
        spellcheck: false,
        plainPaste: true,
        enableScript: false,
        imageButtons: ["floatImageLeft", "floatImageNone", "floatImageRight", "linkImage", "replaceImage", "removeImage"],
        allowedImageTypes: ["jpeg", "jpg", "png", "gif"],
        imageUploadURL: '../sys/oss/upload',
        imageUploadParams: {id: "edit"},
        imagesLoadURL: '../sys/oss/queryAll'
    });

    var code = request("code");
    vm.update(code)
});

var ztree;

var setting = {
    data: {
        simpleData: {
            enable: true,
            idKey: "id",
            pIdKey: "0",
            rootPId: -1
        },
        key: {
            url: "nourl"
        }
    }
};

var vm = new Vue({
	el: '#rrapp',
	data: {
        showList: true,
        title: null,
        imgName: '',
        visible: false,
		standings: {
            typeId: '',
            typeName: ''
        },
		ruleValidate: {
			name: [
				{required: true, message: '名称不能为空', trigger: 'blur'}
			]
		},
		q: {
		    name: ''
		}
	},
	methods: {
        reload: function (event) {
            vm.handleReset('formValidate');
        },
		update: function (code) {
		    debugger
			if (code == null) {
				return;
			}
            vm.title = "编辑";
            vm.standings = {
                typeId: ''

            };
            vm.getInfo(code)
            $('#desc').editable('setHTML', '');
            vm.getType();

		},
		saveOrUpdate: function (event) {
            let url = vm.standings.id == null ? "../standings/save" : "../standings/update";
            vm.standings.desc = $('#desc').editable('getHTML');
            Ajax.request({
			    url: url,
                params: JSON.stringify(vm.standings),
                type: "POST",
			    contentType: "application/json",
                successCallback: function (r) {
                    alert('操作成功', function (index) {
                    });
                }
			});
		},
		del: function (event) {
            let ids = getSelectedRows("#jqGrid");
			if (ids == null){
				return;
			}

			confirm('确定要删除选中的记录？', function () {
                Ajax.request({
				    url: "../standings/delete",
                    params: JSON.stringify(ids),
                    type: "POST",
				    contentType: "application/json",
                    successCallback: function () {
                        alert('操作成功', function (index) {
                            vm.reload();
                        });
					}
				});
			});
		},
		getInfo: function(code){
            Ajax.request({
                url: "../standings/infoByType/"+code,
                async: true,
                successCallback: function (r) {
                    vm.standings = r.standings;
                    $('#desc').editable('setHTML', vm.standings.desc);
                    vm.getType();
                }
            });
		},
        reloadSearch: function() {
            vm.q = {
                name: ''
            }
            vm.reload();
        },
        handleSubmit: function (name) {
            handleSubmitValidate(this, name, function () {
                vm.saveOrUpdate()
            });
        },
        handleReset: function (name) {
            handleResetForm(this, name);
        },

        handleFormatError: function (file) {
            this.$Notice.warning({
                title: '文件格式不正确',
                desc: '文件 ' + file.name + ' 格式不正确，请上传 jpg 或 png 格式的图片。'
            });
        },
        handleMaxSize: function (file) {
            this.$Notice.warning({
                title: '超出文件大小限制',
                desc: '文件 ' + file.name + ' 太大，不能超过 2M。'
            });
        },
	},
});